# -*- coding: utf-8 -*-

import os
import sys

from mtl.mtl_rules import convert_rules
from mtl.mtl_package import convert_package

MTL_DIRNAME = 'mtl'


def generate_mtl(project_path: str):
    # Get the absolute path of the project path.
    project_path = os.path.abspath(project_path)
    # Append project path to system path.
    sys.path.insert(1, project_path)
    # Create the MTL directory.
    mtl_path = os.path.join(project_path, MTL_DIRNAME)
    if not os.path.isdir(mtl_path):
        # Create the MTL path.
        os.makedirs(mtl_path, exist_ok=True)
    # Now check the MTL path.
    if not os.path.isdir(mtl_path):
        raise Exception('Failed to create MTL directory: {}'.format(mtl_path))
    # Import the template.
    convert_package(project_path, mtl_path)
    # Import the rules.
    convert_rules(project_path, mtl_path)
